<template>
  <div>
    <el-tree
        :data="tableData"
        :props="defaultProps"
        ref="menuTree"
        node-key="label"
        active-class="active"
        accordion
        @node-click="handleNodeClick">
      <template class="custom-tree-node" v-slot="{ node, data }">
            <span>
              <span v-if="node.data.evaluateid">({{index1SuccessNum(node)}}/{{node.data.children.length}}) </span>
              <span v-if="node.data.evaluateindex1id&&node.data.evaluateindex2id">({{index2SuccessNum(node)}}/{{node.data.children.length}}) </span>
              <!--              <i class="el-icon-success"></i>-->

              <i class="el-icon-star-on" v-show="node.data.evaluateindex3id&&node.data.success"></i>
              <i class="el-icon-star-off" v-show="node.data.evaluateindex3id&&!node.data.success"></i>
              {{ node.label}}
            </span>
      </template>
    </el-tree>
  </div>
</template>

<script>
import variables from "@/assets/variables.scss";

export default {
  data() {
    return {
      data: [{
        label: '一级 1',
        children: [{
          label: '二级 1-1',
          children: [{
            label: '三级 1-1-1'
          }]
        }]
      }],
      tableData:null,
      defaultProps: {
        children: 'children',
        label: 'label'
      }
    };
  },
  methods: {
    handleNodeClick(data) {
      console.log(data);
    },
    getData() {
      axios.get("http://localhost:8081/evaluatetree/双山实验小学").then((res)=>{
        console.log(res.data)
        this.$store.commit('setTreeTable',res.data)
        this.tableData= this.$store.state.treeTable
        console.log(this.tableData)
      })
    }
  },
  mounted() {
    this.getData()
  },
  computed:{
    index1SuccessNum(){
      return function (no){
        // console.log('计算属性参数',no)
        let cnt=0
        for (let i of no.data.children){
          let flag=1;
          for (let j of i.children){
            if (!j.success){
              flag=0
              break;
            }
          }
          if(flag) {
            cnt+=1
          }
        }
        return cnt;
      }
    },
    // 统计二级指标完成数
    index2SuccessNum(){
      return function (no){
        let cnt=0;
        for (let i of no.data.children){
          if(i.success){
            cnt++
          }
        }
        return cnt
      }
    },
    variables() {
      return variables
    },

  },

};
</script>

<style scoped>

</style>
